﻿using BLL.Interface;
using DAL.Interface;
using Microsoft.EntityFrameworkCore;
using Model;
using Model.DTO.Public.GetList;
using Model.Entity.Type;

namespace BLL
{
    /// <summary>
    /// 性别类型业务逻辑层
    /// </summary>
    public class GenderTypeBLL : IGenderTypeBLL
    {
        private readonly IBaseDAL<TB_GenderType> _genderTypeDAL;
        public GenderTypeBLL(IBaseDAL<TB_GenderType> genderTypeDAL)
        {
            _genderTypeDAL = genderTypeDAL;
        }
        /// <summary>
        /// 获取性别类型列表
        /// </summary>
        /// <param name="param"></param>
        /// <returns></returns>
        public async Task<ResponseMessage> GetGenderTypeList(GetListDTO param)
        {
            try
            {
                #region 参数校验
                if (param.Page <= 0)
                {
                    param.Page = 1;
                }
                if (param.Size <= 0)
                {
                    param.Size = 10;
                }
                #endregion
                var genderTypes = await _genderTypeDAL.GetEntityAllAsync(x => x.Name.Contains(param.Query ?? string.Empty));
                var total = await genderTypes.CountAsync();
                var list = await genderTypes.Skip((param.Page - 1) * param.Size).Take(param.Size).ToListAsync();
                return ResponseMessage.CreateSuccess("获取成功", new { total, list });
            }
            catch
            {
                return ResponseMessage.CreateError("获取失败");
            }
        }
    }
}
